﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Cs期中作业
{
    public partial class 查询宿舍 : Form
    {
        public 查询宿舍()
        {
            InitializeComponent();
        }

        private void srhBtn_Click(object sender, EventArgs e)
        {
            StringBuilder ipS = new StringBuilder();
            StringBuilder dbS = new StringBuilder();
            StringBuilder dormShS = new StringBuilder();
            StringBuilder sqlUserS = new StringBuilder();
            StringBuilder sqlPwS = new StringBuilder();
            Gen.GetPrivateProfileString("Host", "Server", "localhost", ipS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "Database", "Dorm", dbS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "DormSheet", "Dorm", dormShS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "UserName", "", sqlUserS, 255, @".\config.ini");
            Gen.GetPrivateProfileString("SQL", "Password", "", sqlPwS, 255, @".\config.ini");
            string ip = ipS.ToString();
            string db = dbS.ToString();
            string dormSh = dormShS.ToString();
            string sqlUser = sqlUserS.ToString();
            string sqlPw = sqlPwS.ToString();
            string connString = "Data Source=" + ip + ";Initial Catalog=" + db + ";Persist Security Info=True;User ID=" + sqlUser + ";Password=" + sqlPw;
            SqlConnection con = new SqlConnection(connString);
            string sql = "select * from " + dormSh + " where 楼号 like'" + BudNo.Text + "' and 宿舍号 like '" + dormNo.Text + "'";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
            DataSet dataSet = new DataSet("宿舍");
            dataAdapter.Fill(dataSet);

            dataGridView1.DataSource = dataSet.Tables[0];
            dataGridView1.Columns[0].HeaderText = "楼号";
            dataGridView1.Columns[1].HeaderText = "宿舍号";
            dataGridView1.Columns[2].HeaderText = "是否住满";
            dataGridView1.Columns[3].HeaderText = "可住/满员";
        }

        private void BackBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
